// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
const userListDB = db.collection('userList');
const result = {
    bLoginState: false,
    sProjectName: '',
}
// 云函数入口函数
exports.main = (event, context) => {
    return new Promise((resolve, reject) => {
        var sUser = event.sUser;
        var sPassword = event.sPassword;

        userListDB.get().then((res) => {
            let userInfo = res.data;
            if (userInfo && userInfo.length > 0) {
                for (var i = 0; i < userInfo.length; i++) {
                    if (sUser == userInfo[i]._userName && (sPassword == userInfo[i]._password)) {
                        result.bLoginState = true;
                        result.sProjectName = userInfo[i]._project;
                        resolve(result);
                        return;
                    }
                }
                result.bLoginState = false;
                result.sProjectName = '';
                resolve(result);
            }
        })
    })
}
